package com.gh.plugin.maintest;

import android.app.Activity;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.gh.plugin.main.dialog.main.custom.DragFloatView;

public class PluginMgr {
    Activity activity;
    Resources resources;
    DragFloatView dragFloatView;
    PopupWindow pop;

    public PluginMgr(Activity activity,Resources resources) {
        this.activity = activity;
        this.resources = resources;
    }

    public  void show(){
        dragFloatView = new DragFloatView(activity);
        ViewGroup contentView =  activity. findViewById(android.R.id.content);


        final View dialog_icon =activity. getLayoutInflater().inflate(resources.getLayout(R.layout.dialog_icon), null);

        dragFloatView.addView(dialog_icon);

        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        contentView. addView(dragFloatView,layoutParams);



        final View layout =activity. getLayoutInflater().inflate(R.layout.dialog_main, null);
        final RelativeLayout relativeLayout = layout.findViewById(R.id.root_viewpager);
        final View layout1 =activity. getLayoutInflater().inflate(R.layout.main_page_acc, null);
        final View layout2 =activity. getLayoutInflater().inflate(R.layout.main_page_clicker, null);
        final View layout3 =activity. getLayoutInflater().inflate(R.layout.main_page_giftcode, null);
        pop = new PopupWindow(layout,
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT,
                false);
        pop.setBackgroundDrawable(new ColorDrawable(0xffffff));//支持点击Back虚拟键退出

        layout. findViewById(R.id.cl_bottombar_tabbtn_1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //   Toast.makeText(getApplicationContext(),"加速",1).show();
                relativeLayout.removeAllViews();
                relativeLayout.addView(layout1);
            }
        });
        layout. findViewById(R.id.cl_bottombar_tabbtn_2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                relativeLayout.removeAllViews();
                relativeLayout.addView(layout2);
            }
        });
        layout. findViewById(R.id.cl_bottombar_tabbtn_3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                relativeLayout.removeAllViews();
                relativeLayout.addView(layout3);
            }
        });
        layout. findViewById(R.id.cl_bottombar_tabbtn_4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(activity ,"攻略",Toast.LENGTH_LONG).show();
            }
        });
        layout. findViewById(R.id.rl_blank).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop.dismiss();
                dragFloatView.setVisibility(View.VISIBLE);
            }
        });

        dragFloatView .setOnClickListener(new DragFloatView.OnClickListener() {
            @Override
            public void onClick() {
//                LayoutInflater inflater = LayoutInflater.from(getApplication());
//                View view = inflater.inflate(R.layout.dialog_main, null);
//                AlertDialog.Builder builder=new AlertDialog.Builder(TestActivity.this);
//                builder.setView(view);

//                dialog=builder.create();
//                dialog.show();



                pop.showAtLocation(dragFloatView, Gravity.NO_GRAVITY, 0, 0);
                dragFloatView.setVisibility(View.GONE);
                relativeLayout.removeAllViews();
                relativeLayout.addView(layout1);

//                ViewPager vpPager = (ViewPager)layout. findViewById(R.id.root_viewpager);
//                TabsPagerAdapter  myAdapter = new TabsPagerAdapter( getSupportFragmentManager());
//                vpPager.setAdapter(myAdapter);
            }
        });

    }

    public XmlResourceParser getPluginLayout() {
        return  resources.getLayout(R.layout.test);

    }
}
